package com.abhinav.designPatterns.adapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

// Adapter
public class SortListAdapter implements Sorter {

	@Override
	public int[] sort(int[] numbers) {
		// convert the array to a List
		List<Integer> numberList = new ArrayList<Integer>();
		for(int i : numbers)
			numberList.add(i);

		// call the adapter
		NumberSorter sorter = new NumberSorter();
		numberList = sorter.sort(numberList);

		// convert the list back to an array and return
		int i = 0;
		Integer[] intList = numberList.toArray(new Integer[0]);
		int[] sortedNumbers = new int[intList.length];
		for (int value : intList) {
			sortedNumbers[i++] = Integer.valueOf(value);
		}
		
		return sortedNumbers;
	}

}
